﻿
//初始化
var fun = "";
if (typeof ($) != "undefined") {
    $(document).ready(function () {

    });
    instance[0].EditDate = new Date();
    instance[0].AddTime = new Date();

    fun = getPar1("fun");
    $("textarea[name='ItemRemark']").css("background", "whitesmoke");
    if (fun == "view") {
        parent.setButtonHiden();
        $("div input").attr("disabled", true).css("background", "whitesmoke");
        $("div textarea").css("background", "whitesmoke");
        $("div select").attr("disabled", true).css("background", "whitesmoke");
        $("div input[type=button]").hide();
        setTimeout(HideButton, 200);
    }
}

function HideButton() {
    $("#ExaminationSolutionItem thead:first-child").hide();
}


//修改查看时加载数据begin

//修改查看时加载数据,obj-行对象
var fnCustomeGetDataSourceEvent = function (obj,indexRow) {
    fnCreateItemTypeSelect(obj,indexRow);
}

//项目分类下拉框,obj-行对象
var fnCreateItemTypeSelect = function (obj,indexRow) {
    var ItemCateoryIDObj = document.getElementsByName("ItemCateoryID")[indexRow];
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=createitemtypeselect", {
        success: function (res) {
            try {
                var str = res.responseText;
                //debugger;
                $(ItemCateoryIDObj).empty();
                $(ItemCateoryIDObj).append(str);
                if (fun != "add") {
                    //alert(document.getElementsByName("ItemCateoryID").length);
                    //下面两种设置方法都可以的
                    $(ItemCateoryIDObj).val(_DataTable.Rows[indexRow].ItemCateoryID);
                    //jsSelectItemByValue(ItemCateoryIDObj, _DataTable.Rows[indexRow].ItemCateoryID);
                }
                //jsSelectGetSelectOption(ItemCateoryIDObj);
                $(ItemCateoryIDObj).bind("change", fnCreateItemSelect(ItemCateoryIDObj,indexRow));
            }
            catch (e) { }
            finally { }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}

//项目下拉框,obj-行对象
var fnCreateItemSelect = function (obj,indexRow) {
    //debugger;
    var ItemCateoryIDObj = obj;
    var cateoryID = $(ItemCateoryIDObj).val();
    //var cateoryID = jsSelectGetSelectOption(ItemCateoryIDObj);
    //alert("cateoryID:" + cateoryID);
    var ItemIDObj = document.getElementsByName("ItemID")[indexRow];
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=createitemselect" + "&cateoryID=" + cateoryID, {
        success: function (res) {
            try {
                var str = res.responseText;
                //debugger;
                $(ItemIDObj).empty();
                $(ItemIDObj).append(str);
                if (fun != "add") {
                    //下面两种设置方法都可以的
                    $(ItemIDObj).val(_DataTable.Rows[indexRow].ItemID);
                    //jsSelectItemByValue(ItemIDObj, _DataTable.Rows[indexRow].ItemID);
                    fnItemSelect(ItemIDObj,indexRow);
                }
                $(ItemIDObj).bind("change", fnItemSelect(ItemIDObj, indexRow));
            }
            catch (e) { }
            finally { }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}

//项目下拉框选择事件,obj-行对象
var fnItemSelect = function (obj,indexRow) {
    var ItemID = $(obj).val();
    var ItemName = $(obj).find("option:selected").text()
    //alert("ItemID:" + ItemID + " ItemName:" + ItemName);
    var ItemRemarkObj = document.getElementsByName("ItemRemark")[indexRow];

    var url = "../Extend/AjaxData/jsonlist.aspx?entity=ExaminationItem&condition=ID='" + ItemID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            //debugger;
            var t = list.rows[o].Remark;
            if (typeof (t) != "undefined") {
                $(ItemRemarkObj).val(t);
            }
        }
    });
}

//修改查看时加载数据end

//新增行时触发事件begin

//新增行时触发事件,obj-行对象
var fnCustomeRowAddEvent = function (obj, indexRow) {
    $("#Seq", obj).val(indexRow + 1);
    $("textarea[name='ItemRemark']").css("background", "whitesmoke");
    fnCreateItemTypeSelectAdd(obj, indexRow);
}

//新增时，项目分类下拉框,obj-行对象
var fnCreateItemTypeSelectAdd = function (obj, indexRow) {
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=createitemtypeselect", {
        success: function (res) {
            try {
                var str = res.responseText;
                //debugger;
                $("#ItemCateoryID", obj).empty();
                $("#ItemCateoryID", obj).append(str);
                $("#ItemCateoryID", obj).bind("change", fnCreateItemSelectAdd(obj));
            }
            catch (e) { }
            finally { }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}

//项目分类下拉框OnChange,obj-当前行this
var fnOnChangeItemTypeSelect = function (obj) {
    fnCreateItemSelectAdd(getTableRow(obj));
}

//项目下拉框,obj-行对象
var fnCreateItemSelectAdd = function (obj) {
    //debugger;
    var cateoryID = $("#ItemCateoryID", obj).val();
    //alert("cateoryID:" + cateoryID);
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=createitemselect" + "&cateoryID=" + cateoryID, {
        success: function (res) {
            try {
                var str = res.responseText;
                //debugger;
                $("#ItemID", obj).empty();
                $("#ItemID", obj).append(str);
                $("#ItemID", obj).bind("change", fnItemSelectAdd(obj));
            }
            catch (e) { }
            finally { }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}

 //项目下拉框OnChange，obj-当前行this
 var fnOnChangeItemSelect = function (obj) {
     fnItemSelectAdd(getTableRow(obj));
 }

 //项目下拉框选择事件,obj-行对象
 var fnItemSelectAdd = function (obj) {
     var ItemID = $("#ItemID",obj).val();
     var url = "../Extend/AjaxData/jsonlist.aspx?entity=ExaminationItem&condition=ID='" + ItemID + "'";
     $.get(url, function (d, s) {
         var list = eval("(" + d + ")");
         for (var o in list.rows) {
             //debugger;
             var t = list.rows[o].Remark;
             if (typeof (t) != "undefined") {
                 $("#ItemRemark",obj).val(t);
             }
         }
     });
 }
 //新增行时触发事件end

 var fnCheckData = function () {
     try {
         if ($("#SolutionName").val() == "") {
             return "方案名字不能为空！";
         }
         if ($("#Seq").val() == "") {
             return "序号不能为空！";
         }

     }
     catch (e)
     { }
 }

 ///设置select中Value="paraValue"的第一个Item为选中  
 function jsSelectItemByValue(objSelect, objItemValue) {
     //debugger;
     //判断是否存在        
     for (var i = 0; i < objSelect.options.length; i++) {
         if (objSelect.options[i].value == objItemValue) {
             objSelect.options[i].selected = true;
             break;
         }
     }
 }

 // 1.判断select选项中 是否存在Value="paraValue"的Item        
 function jsSelectGetSelectOption(objSelect) {
     //debugger;
     var v = "";
     for (var i = 0; i < objSelect.options.length; i++) {
         if (objSelect.options[i].selected == true) {
             v = objSelect.options[i].value;
             break;
         }
     }
     return v;
 }   














